
package com.scalar.chiptrack.proxy;

import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Calendar;
import java.util.Date;

/**
* Logger writes a message to the log file and optionally to stderr
*/

class Logger {

    static PrintStream log = null ;
    static String LogFile ;
	static Calendar s_cal = Calendar.getInstance();

    public Logger(String LogFile) {
    	Logger.LogFile = LogFile ;

    }

    public synchronized void It(String sLine, int iLevel) {
        if(log == null) {
            try {
                log = new PrintStream(
                new BufferedOutputStream(
                new AppendFileOutputStream(LogFile))) ;
            }
            catch(IOException e) {}

            // write separator for start of new log entries
            log.println("#####################################################") ;
        }

        Date today = new Date() ;

        log.println (s_cal.get (Calendar.YEAR) + "/" + (s_cal.get (Calendar.MONTH) + 1) + "/" + s_cal.get (Calendar.DATE) + " " +
                     s_cal.get (Calendar.HOUR_OF_DAY) + ":" + s_cal.get (Calendar.MINUTE) + ":" + s_cal.get (Calendar.SECOND) + " " +
                     Thread.currentThread().getName() + "," + sLine) ;
        log.flush() ;

        if(iLevel > 1) {
            System.err.println (s_cal.get (Calendar.YEAR) + "/" + (s_cal.get (Calendar.MONTH) + 1) + "/" + s_cal.get (Calendar.DATE) +
                                " " + s_cal.get (Calendar.HOUR_OF_DAY) + ":" + s_cal.get (Calendar.MINUTE) + ":" + s_cal.get (Calendar.SECOND) +
                                " " + Thread.currentThread().getName() + "," + sLine) ;
        }
    }
}